# Maintainer: Jelle van der Waa <jelle@archlinux.org>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Jingbei Li <i@jingbei.li>

pkgname=libwebsockets
pkgver=4.3.2
pkgrel=3
pkgdesc="C library for websocket clients and servers"
arch=(x86_64)
url="https://libwebsockets.org"
license=(MIT)
depends=(glibc openssl libuv libev zlib)
makedepends=(cmake glib2 libcap)
provides=(libwebsockets.so)
source=($pkgname-$pkgver.tar.gz::https://github.com/warmcat/$pkgname/archive/v$pkgver.tar.gz)
sha512sums=('68d18574dea0563fa4f080c5d0d1cfe21a115bffdb17c6190f6741998f1e5db0739e252ef344ffe6fa4bd6781372456b240539471dd2aa900e43759e0f2d42ad')
b2sums=('3b8657b79828102cbfba71ea789acd3b7aec7faaa6317974d182b3cb4b5091d8efcf1f184278f71674624a0f1968450ab056e1d91f9faf2c35c67c6c6f4cb695')

build() {
  cmake -D CMAKE_INSTALL_PREFIX=/usr \
        -D CMAKE_BUILD_TYPE=None \
        -D DISABLE_WERROR=ON \
        -D LWS_IPV6=ON \
        -D LWS_LINK_TESTAPPS_DYNAMIC=ON \
        -D LWS_WITH_ACME=ON \
        -D LWS_WITH_DISKCACHE=ON \
        -D LWS_WITH_EXTERNAL_POLL=ON \
        -D LWS_WITH_FTS=ON \
        -D LWS_WITH_GLIB=ON \
        -D LWS_WITH_HTTP2=ON \
        -D LWS_WITH_HTTP_PROXY=ON \
        -D LWS_WITH_LIBEV=ON \
        -D LWS_WITH_LIBEVENT=OFF \
        -D LWS_WITH_LIBUV=ON \
        -D LWS_WITH_LWSAC=ON \
        -D LWS_WITH_RANGES=ON \
        -D LWS_WITH_SOCKS5=ON \
        -D LWS_WITH_STATIC=OFF \
        -D LWS_WITH_THREADPOOL=ON \
        -D LWS_WITH_ZIP_FOPS=ON \
        -D LWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
        -D LWS_WITHOUT_BUILTIN_SHA1=ON \
        -D LWS_WITHOUT_CLIENT=OFF \
        -D LWS_WITHOUT_SERVER=OFF \
        -D LWS_WITHOUT_TESTAPPS=ON \
        -D LWS_WITHOUT_TEST_CLIENT=ON \
        -D LWS_WITHOUT_TEST_PING=ON \
        -D LWS_WITHOUT_TEST_SERVER=OFF \
        -D LWS_WITHOUT_TEST_SERVER_EXTPOLL=ON \
        -D LWS_UNIX_SOCK=ON \
        -Wno-dev \
        -B build \
        -S $pkgname-$pkgver
  make VERBOSE=1 -C build
}

package() {
  depends+=(libcap.so libglib-2.0.so)

  make DESTDIR="$pkgdir" install -C build
  install -vDm 644 $pkgname-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
